//
//  CommentCell.m
//  MeiXiu
//
//  Created by Yuan on 12-10-31.
//
//

#import "CommentCell.h"
#import <QuartzCore/QuartzCore.h>

@implementation CommentCell
@synthesize iconButton;//头像
@synthesize aliasLable; //昵称
@synthesize timeLbl; //时间
@synthesize contentLbl;//评论
@synthesize commentButton;
@synthesize replyView;

-(void)dealloc
{
    [replyView release];replyView = nil;
    [aliasLable release];aliasLable = nil;
    [timeLbl release];timeLbl = nil;
    [contentLbl release];contentLbl = nil;
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        CGFloat margin_top = 7.0f;

        iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [iconButton setFrame:CGRectMake(10,margin_top, 40,40)];
        iconButton.layer.cornerRadius = 6.0;
        [iconButton setUserInteractionEnabled:YES];
        iconButton.layer.masksToBounds = YES;
        [self.contentView addSubview:iconButton];
        
        aliasLable = [[UILabel alloc]initWithFrame:CGRectMake(60.0f, margin_top-2.0, 150.0f, 25.0f)];
        [aliasLable setTextColor:[UIColor colorWithRed:0.720 green:0.225 blue:0.165 alpha:1.000]];
        [aliasLable setFont:[UIFont systemFontOfSize:16.0]];
        [aliasLable setContentMode:UIViewContentModeScaleAspectFit];
        [aliasLable setBackgroundColor:[UIColor clearColor]];
        [aliasLable setAdjustsFontSizeToFitWidth:YES];
        [self.contentView addSubview:aliasLable];
        
        timeLbl = [[UILabel alloc]initWithFrame:CGRectMake(60.0f, margin_top+22, 150.0f, 18.0f)];
        [timeLbl setTextColor:[UIColor grayColor]];
        [timeLbl setFont:[UIFont systemFontOfSize:14.0]];
        [timeLbl setContentMode:UIViewContentModeScaleAspectFit];
        [timeLbl setBackgroundColor:[UIColor clearColor]];
        [timeLbl setAdjustsFontSizeToFitWidth:YES];
        [self.contentView addSubview:timeLbl];
        
        contentLbl = [[UITextView alloc] initWithFrame:CGRectMake(52.0f,40.0f,260.0f,80.0f)];
        [contentLbl setEditable:NO];
        [contentLbl setDataDetectorTypes:UIDataDetectorTypeAll];
        [contentLbl setFont:[UIFont systemFontOfSize:16.0]];
        [contentLbl setTextColor:[UIColor blackColor]];
        [contentLbl setUserInteractionEnabled:YES];
        [contentLbl setBackgroundColor:[UIColor clearColor]];
        [self.contentView addSubview:contentLbl];
        
        commentButton = [UIButton buttonWithType:UIButtonTypeCustom];        
        [commentButton setImage:[UIImage imageNamed:@"reply_button"] forState:UIControlStateNormal];
        [commentButton setImage:[UIImage imageNamed:@"reply_button"] forState:UIControlStateHighlighted];
        [commentButton setFrame:CGRectMake(250,13.0,78/1.5,25/1.5)];
        [commentButton setUserInteractionEnabled:YES];
        [self.contentView addSubview:commentButton];
        
        replyView = [[ReplyView alloc]initWithFrame:CGRectMake(60.0f,0,252, 0)];
        [self.contentView addSubview:replyView];
        
    }
    return self;
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    
    CGRect cRect = contentLbl.frame;
    cRect.size.height = contentLbl.contentSize.height;
    contentLbl.frame = cRect;
    
    CGRect rRect = replyView.frame;
    rRect.origin.y = cRect.origin.y+cRect.size.height+2;
    replyView.frame = rRect;
    
    self.clipsToBounds = YES;
    CGRect rect = self.contentView.frame;
    rect.size.height  = self.frame.size.height;
    self.contentView.frame = rect;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
//    [self setLabelSelect:selected];
}
/*
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    
    [super setHighlighted:highlighted animated:animated];
    [self setLabelSelect:highlighted];
}

-(void)setLabelSelect:(BOOL)selected{
    
    if (selected)
    {
        self.timeLbl.textColor=[UIColor whiteColor];
        self.aliasLable.textColor=[UIColor whiteColor];
        self.contentLbl.textColor=[UIColor whiteColor];
    }
    else
    {
        self.timeLbl.textColor=[UIColor whiteColor];
        [aliasLable setTextColor:[UIColor colorWithRed:0.720 green:0.225 blue:0.165 alpha:1.000]];
        [timeLbl setTextColor:[UIColor grayColor]];
        self.contentLbl.textColor=[UIColor blackColor];
    }
}
*/

@end
